 <?php require_once ADMINVIEWPATH.'admin_header.php'; ?>
<?php require_once ADMINVIEWPATH.'admin_menu.php'; ?>
 <link href="<?= STATICURL; ?>css/bootstrap.min.css" rel="stylesheet" />
    <link id="bootstrap-rtl-link" href="" rel="stylesheet" />
    <link id="beyond-link" href="<?= STATICURL; ?>css/beyond.min.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" type="text/css" href="<?=STATICURL;?>css/oss_style.css"/>
    <div class="page-content">
     <!-- Page Breadcrumb -->
        <div class="page-breadcrumbs">
            <ul class="breadcrumb">
                <li>
                    <i class="fa fa-home"></i>
                    <a href="/luckydog/index">首页</a>
                </li>
                <li class="">
                    <a href="#">新闻管理</a>
                </li>
                <li class="">
                    新闻编辑
                </li>
            </ul>
        </div>
        <!-- /Page Breadcrumb -->
        <div class="page-body">
            <div >
                <div id="horizontal-form">
                    <form class="form-horizontal" role="form">
                        <div class="row">
                            <div class="col-md-6">
                                <div class="pull-left" style="line-height: 30px;margin-left: 10px;margin-bottom: 20px;">标题:</div>
                                <div style="float: left; padding-left:10px;">
                                    <input type="text" style="width: 400px;" name="title" placeholder="请输入标题" class="form-control" value="<?= $NewsInfo['title']?>">
                                </div>
                                <div class="horizontal-space"></div>
                            </div>
                            <div class="col-md-6">
                                <div class="pull-left" style="line-height: 30px;margin-left: 10px;margin-bottom: 20px;">来源:</div>
                                <div style="float: left; padding-left:10px;">
                                    <input type="text" style="width: 400px;" name="transferfrom" placeholder="请输入来源" class="form-control" value="<?=$NewsInfo['transferfrom']?>">
                                </div>
                                <div class="horizontal-space"></div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-6">
                                <div class="pull-left" style="line-height: 30px;margin-left: 10px;margin-bottom: 20px;">分类:</div>
                                <div style="float: left; padding-left:10px;">
                                <select class="form-control it_categoryid">
                                    <option value="0">-----请选择新闻分类----</option>
                                    <?php foreach($catList as $cat):?>
                                    <option  value="<?= $cat['cat_id']?>"  <?php if($NewsInfo['categoryid'] == $cat['cat_id']):?>selected<?php endif;?>>
                                        <?=$cat['cat_name']?>
                                    </option>
                                    <?php endforeach;?>
                                </select>
                                </div>
                                <div class="horizontal-space"></div>
                            </div>

                            <div class="col-md-6">
                                <div class="pull-left" style="line-height: 30px;margin-left: 10px;margin-bottom: 20px;">积分:</div>
                                <div style="float: left; padding-left:10px;">
                                    <input type="text"  style="width: 400px;" name="point" placeholder="请输入积分(数字)" class="form-control point" value="<?=$NewsInfo['point']?>">
                                <div class="horizontal-space"></div>
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="pull-left" style="line-height: 30px;margin-left: 25px;margin-bottom: 20px;">省:&nbsp;&nbsp;</div>
                            <div class="col-md-2">
                                <select class="form-control it_province">
                                    <option value="0">---请选择省--</option>
                                    <?php foreach($provinceList as $pro):?>
                                    <option  value="<?= $pro['id']?>"  <?php if($NewsInfo['provinceid'] == $pro['id']):?>selected<?php endif;?>>
                                        <?=$pro['name']?>
                                    </option>
                                    <?php endforeach;?>
                                </select>
                                <div class="horizontal-space"></div>
                            </div>
                            <div class="pull-left" style="line-height: 30px;margin-left: 10px;margin-bottom: 20px;">市:</div>
                            <div class="col-md-2">
                                <select class="form-control it_city">
                                    <option value="0">---请选择市--</option>
                                    <?php foreach($cityList as $city):?>
                                    <option   value="<?= $city['id']?>"  <?php if($NewsInfo['cityid'] == $city['id']):?>selected<?php endif;?>>
                                        <?=$city['name']?>
                                    </option>
                                    <?php endforeach;?>
                                </select>
                                <div class="horizontal-space"></div>
                            </div>
                            <div class="col-md-6" style="padding-left: 165px;">
                            <label>是否是推荐</label>
                                <label>
                                    <input  <?php if($NewsInfo['readonly'] == "1"):?>checked=""<?php endif;?>  class="checkbox-slider toggle colored-blue readonly" type="checkbox">
                                    <span class="text"></span>
                                </label>
                                <div class="horizontal-space"></div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-6">
                            <label>是否是软文</label>
                                <label>
                                    <input  <?php if($NewsInfo['isruanwen']):?>checked=""<?php endif;?>  class="checkbox-slider toggle colored-blue ruanwen" type="checkbox">
                                    <span class="text"></span>
                                </label>
                                <div class="horizontal-space"></div>
                            </div>
                            <div class="col-md-6 totalmoney_view" style="<?php if(!$NewsInfo['isruanwen']):?>display:none<?php endif;?>">
                                <div class="pull-left" style="line-height: 30px;margin-left: 10px;margin-bottom: 20px;">投入金额:</div>
                                <div style="float: left; padding-left:10px;">
                                    <input type="text"  style="width: 400px;" name="totalmoney" placeholder="投入金额(￥)" class="form-control totalmoney" value="<?=$NewsInfo['totalmoney']?>">
                                <div class="horizontal-space"></div>
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div class="horizontal-space"></div>
                            </div>
                        </div>
                        <div class="widget-content">
                        <div style="color:red">（注：图片建议上传图片长宽比1.5:1）</div>
                            <div class='clearfix' style="margin-top:15px;">

                                <div id="container" style="float: left">
                                    <a id="selectfiles" href="javascript:void(0);" class='btn'>选择图片</a>
                                    <a id="postfiles" href="javascript:void(0);" class='btn'>开始上传</a>
                                </div>
                                <span id="console"></span>
                                <?php if($NewsInfo['cover']):?>
                                <span id = "ossfile"  style="position:relative;float:right;margin-left:5px;">
                                    <div class="bg_floating" style="float:right;margin-right:10px;">
                                        <img class="uploadpic" img-original='<?= $NewsInfo['cover'] ?>' src="<?= OSSHOST.$NewsInfo['cover'] ?>" width="120px" height="80px" alt="pic"/>
                                    </div><br />
                                    <a class="del_pic" data_id="<?=$NewsInfo['newsID']?>" style="margin-left:40px;" href="javascript:void(0);">删除</a>
                                </span>
                                <?php else :?>
                                <span id="ossfile" style="position:relative;float:right;margin-left:5px">
                                </span>
                                <?php endif;?>
                            </div>
                        </div>
                       <div style="clear:both;margin-top: 20px;"> 
                        <textarea class="form-control contents" rows="3" id="contents" name="contents" placeholder="Content" style="height:500px;width:80%">
                            <?=$NewsInfo['content']?>
                        </textarea>
			            </div>
                        <div class="horizontal-space"></div>
                        <div>
                            <span id="editNews" class="btn btn-default">提交</span>
                        </div>
                    </form>
                </div>
            </div>
        </div>
        <input type="hidden" id="idpalce" value="<?= $NewsInfo['newsID']?>" />
		
<?php require_once ADMINVIEWPATH.'admin_footer.php'; ?>
<script src="<?= STATICURL; ?>js/jquery.min.js"></script>
<script src="<?= STATICURL; ?>layer/layer.js"></script>
<script src="<?= STATICURL; ?>kindeditor/kindeditor.js"></script>
<script type="text/javascript" src="<?=STATICURL;?>js/latest.js"></script>
<script type="text/javascript" src="<?=STATICURL;?>js/plupload-2.1.2/plupload.full.min.js"></script>
<script type="text/javascript" src="<?=STATICURL;?>js/item-upload.js"></script>
<script>
$(".del_pic").live("click",function(){
    $(this).parent().remove();
});
KindEditor.ready(function(K) {
    window.editor = K.create('#contents');
});
    $(document).ready(function() {
        $(".ruanwen").click(function(){
            var ruanwen = $(".ruanwen").prop("checked");
            if(ruanwen == true)
            {
               $(".totalmoney_view").css("display","block");
            }else{
                $(".totalmoney_view").css("display","none");
            }
        });
        $(".it_province").change(function(){
            var privinceid = $(this).val();
			if(privinceid == 0)
			{
				$(".it_city").html('<option value="0">---请选择市--</option>');
				return false;
			}
            $.post("<?=BASEURL?>luckydog/news/cityList",{privinceid:privinceid},function(data){
                // console.log(data);
                var _option = '<option value="0">---请选择市--</option>';
                $.each(data,function(index,item){
                    _option += '<option value="'+item.id+'">'+item.name+'</option>';
                });
                $(".it_city").html(_option);
            },'json');
        });

        $(".point").bind({
                keyup:function(){
                     var txt = $('.point').val();
                     var reg = /^[\d]+$/;
                     if(!reg.test(txt) ){
                            $(this).val('');
                     }
                },
                focus:function(){
                    if ($(this).val() == 0){
                        $(this).val('');
                    }
                },
                blur:function(){
                    if ($(this).val() == ''){
                        $(this).val(default_order);
                    }                   
                }
        });  
        $(".totalmoney").bind({
                keyup:function(){
                     var txt = $('.totalmoney').val();
                     var reg = /^[\d]+$/;
                     if(!reg.test(txt) ){
                            $(this).val('');
                     }
                },
                focus:function(){
                    if ($(this).val() == 0){
                        $(this).val('');
                    }
                },
                blur:function(){
                    if ($(this).val() == ''){
                        $(this).val(default_order);
                    }                   
                }
        }); 
        $("#editNews").click(function(){
           
             editor.sync();//Js获取值时前面添加
            var contents =editor.html();
            var readonly = $(".readonly").prop("checked");
            if(readonly == true)
            {
                readonly = 1;
            }else{
                readonly = 0;
            }

	        var cover = $(".uploadpic").attr("img-original");
            var title = $("input[name='title']").val();
            var point = $("input[name='point']").val();
            
            var transferfrom = $("input[name='transferfrom']").val();
            var id = $("#idpalce").val();
            var categoryid = $(".it_categoryid").val();
            var provinceid = $(".it_province").val();
            var cityid = $(".it_city").val();
            if(contents == ""){
                layer.msg("内容不能为空");return false;
            }
           
            if(title == ""){
                layer.msg("标题不能为空");return false;   
            }
            if(categoryid == ""){
                layer.msg("新闻类型不能为空");return false;   
            }
            if(cityid == ""){
                layer.msg("请选择省市");return false;   
            }
            var ruanwen = $(".ruanwen").prop("checked");
            var totalmoney = $("input[name='totalmoney']").val();
            if(ruanwen == true)
            {
                ruanwen = 1;
                if(!totalmoney){
                    layer.msg("投入金额不能为空");return false;   
                }
            }else{
                ruanwen = 0;
                totalmoney = 0
            }

            
           
	    $.post("<?=BASEURL?>luckydog/news/editNews", {totalmoney:totalmoney,ruanwen:ruanwen,provinceid:provinceid,cityid:cityid,readonly:readonly, point:point,categoryid:categoryid,"contents":contents,"title":title,"transferfrom":transferfrom,"cover":cover,"id":id}, function(res) {
                if (res) {
                    layer.msg("成功");
                    window.location.href="/luckydog/news/index";
                }else{
                    layer.msg("失败");
                }
            });
        });
    });
</script>